package com.util;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class MyControllerAdvice {

    /**
     * 全局异常捕捉处理
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public Map<String,Object> errorHandler(Exception e){
        LogUtil.info("**********报异常了,代码狗**************");
        e.printStackTrace();
        LogUtil.info(e.getMessage());
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code","3");
        map.put("message","操作失败,服务器异常");
        return map;
    }
}
